home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15 / Database / AbstractRecord.h < prev    next >
Encoding:
Text File  |  1996-04-25  |  6.0 KB  |  184 lines  |  [TEXT/CWIE]

  1. //================================================================================
  2. // Greg Anderson
  3. // db+
  4. //
  5. // Abstract base class for cursors
  6. // 16 May 1994
  7. //================================================================================
  8. #pragma once
  9.  
  10. #ifndef __ABSTRACTRECORD__
  11. #define __ABSTRACTRECORD__
  12.  
  13. //
  14. // TTransactionAwareObject is the base class of TAbstractRecord
  15. //
  16. #include "TransactionAwareObject.h"
  17.  
  18. //
  19. // We return cursors of different classes, so we need the
  20. // full definition of all of them.
  21. //
  22. #include "ReferenceTemplates.h"
  23.  
  24. //
  25. // For CompareEnumeration
  26. //
  27. #include "AbstractData.h"
  28.  
  29. //
  30. // For REQUIREVALIDPOINTER
  31. //
  32. #include "Exceptions.h"
  33.  
  34. class TDatabaseDocument;
  35. class TGroupControlObject;
  36.  
  37. //
  38. // This identifier is used to indicate the absence of a record
  39. //
  40. const long kNilIndex = -1;
  41.  
  42. //
  43. // TDBElement and TDBProperty are the two
  44. // derived classes of TAbstractRecord.  The low level
  45. // code knows nothing about their contents, but provides
  46. // two virtual methods to do safe downcasting.
  47. //
  48. class TDBRecord;
  49. class TDBElement;
  50. class TDBProperty;
  51. class TDataRecord;
  52.  
  53. //================================================================================
  54. // Class TAbstractRecord
  55. //================================================================================
  56. class TAbstractRecord : public TTransactionAwareObject
  57. {
  58.     //
  59.     // ----- Fields --------------------------------------------------------------
  60.     //
  61. protected:
  62.     TDatabaseDocument*                    fDocument;
  63.     TGroupControlObject*                fGroupControlObject;
  64.     long                                fRecordIndex;
  65.     long*                                fChangeImage;
  66.     
  67.     unsigned char                        fChangeImageUnchanged;
  68.     unsigned char                        fChangeImageMayHaveChangedBack;
  69.     
  70.     //
  71.     // ----- Methods -------------------------------------------------------------
  72.     //
  73. private:
  74.     void                                CacheGroupControlObject();
  75.  
  76. public:
  77.                                         TAbstractRecord(TDatabaseDocument* doc, long recordIndex);
  78.     virtual                                ~TAbstractRecord();
  79.     
  80.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  81.     // Methods of TTransactionAwareObject:
  82.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  83.     
  84.     virtual Int64                        ObjectsKeySpace() const;
  85.     virtual long                        ObjectKey() const        { return fRecordIndex; };
  86.  
  87. protected:
  88.     virtual void                        CommitChanges(TTransaction* transaction);
  89.     virtual void                        DiscardChanges(TTransaction* transaction);
  90.     
  91.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  92.     // Public interface:  const methods
  93.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  94.  
  95. public:
  96.  
  97.     TDatabaseDocument*                    DBDocument() const { return fDocument; };
  98.  
  99.     //
  100.     // Delete this if we can
  101.     //
  102.     virtual Boolean                        RemoveReference() const;
  103.     virtual void                        DisposeRecordIfUnreferenced();
  104.  
  105.     long                                RecordIndex() const { return fRecordIndex; };
  106.  
  107.     virtual AConst<TAbstractRecord>        GetRecordCursor(long recordIndex) const;
  108.     virtual AConst<TDBRecord>            GetDBRecordCursor(long recordIndex) const;
  109.     virtual AConst<TDBElement>            GetDBElementCursor(long recordIndex) const;
  110.     virtual AConst<TDBProperty>            GetDBPropertyCursor(long recordIndex) const;
  111.     virtual AConst<TDataRecord>            GetDataCursor(long recordIndex) const;
  112.                                 
  113.     AConst<TAbstractRecord>                RecordCursor() const { return AConst<TAbstractRecord>(this); }
  114.     AConst<TDBRecord>                    DBRecordCursor() const { return AConst<TDBRecord>(this->AbstractDBRecord()); }
  115.     AConst<TDBElement>                    DBElementCursor() const { return AConst<TDBElement>(this->DBElementRecord()); }
  116.     AConst<TDBProperty>                    DBPropertyCursor() const { return AConst<TDBProperty>(this->DBPropertyRecord()); }
  117.     AConst<TDataRecord>                    DataCursor() const { return AConst<TDataRecord>(this->DataRecord()); }
  118.         
  119.     //
  120.     // Get data from cursor
  121.     //
  122.     long                                GetRecordData(TTransaction* transaction, long longwordNumber) const;
  123.     Boolean                                ThisRecordIsFree(TTransaction* transaction) const;
  124.  
  125.     //
  126.     // Compare contents of record with something
  127.     //
  128.     CompareEnumeration                    CompareRecordData(TTransaction* transaction, long dataType, long longwordNumber, long numberOfBytes, const TAbstractDataReference& compareWith) const;
  129.     Boolean                                RecordDataContains(TTransaction* transaction, long dataType, long longwordNumber, long numberOfBytes, const TAbstractDataReference& compareWith) const;
  130.     
  131.     //
  132.     // Do debugging tests on this node
  133.     //
  134.     virtual void                        Verify(TTransaction* t, Boolean verifyDeep = false) const = 0;
  135.     
  136.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  137.     // Public interface:  non-const methods
  138.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  139.  
  140. public:
  141.     
  142.     //
  143.     // Change data in cursor (but change isn't permanent until CommitChanges
  144.     // is called)
  145.     //
  146.     void                                ChangeRecordData(TTransaction* transaction, long longwordNumber, long newValue);    
  147.     virtual void                        FreeOwnedData(TTransaction* transaction);
  148.     virtual void                        FreeThisRecord(TTransaction* transaction);
  149.     
  150.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  151.     // Protected interface:
  152.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  153.  
  154.     //
  155.     // Only called from TGroupControlObject::WriteThroughToTransaction
  156.     //
  157.     void                                WriteThroughToTransaction(long longwordNumber, long theData, long theMask);
  158.  
  159. protected:
  160.  
  161.     TGroupControlObject*                GroupControlObject() const { REQUIREVALIDPOINTER(fGroupControlObject); return fGroupControlObject; };
  162.     Boolean                                HasGroupControlObject() const { return fGroupControlObject != nil; }
  163.     
  164.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  165.     // Private methods:
  166.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  167.  
  168.     //
  169.     // Used by compare methods to get a reference to the
  170.     // record's in-line data
  171.     //
  172.     const TConstDataReference            RecordDataReference(TTransaction* transaction, long dataType, long longwordNumber, long numberOfBytes) const;
  173.  
  174. private:
  175.  
  176.     //
  177.     // Used at commit/discard time to add/return a free record
  178.     // to the free list.
  179.     //
  180.     void                                PushRecordIfFree(TTransaction* transaction);
  181. };
  182.  
  183. #endif
  184.